﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;

namespace WindowsApplication4
{
    public partial class Form2 : Form
    {
        List<DataTable> data;
        public Form2(List<DataTable> data)
        {
            this.data = data;
            InitializeComponent();
            BindData();
        }

        public Form2(DataTable dt)
        {
            this.data = new List<DataTable>();
            this.data.Add(dt);
            InitializeComponent();
            BindData();
        }

        private void BindData()
        {
            foreach (DataTable  dt  in data)
            {
                AddTabItem(dt);
            }
        }

        private void AddTabItem(DataTable dt)
        {
            if (dt == null)
                return;
            TabPage tabPage = new TabPage();
            tabPage.Location = new System.Drawing.Point(4, 21);
            tabPage.Padding = new System.Windows.Forms.Padding(3);
            tabPage.Size = new System.Drawing.Size(413, 264);
            tabPage.TabIndex = tabControl1.TabCount;
            tabPage.Text = dt.TableName;
            tabPage.UseVisualStyleBackColor = true;
            tabControl1.TabPages.Add(tabPage);
            GridControl grid = new GridControl();
            
            grid.Location = new Point(0, 0);
            grid.DataSource = dt;
            grid.Dock = DockStyle.Fill;
            tabPage.Controls.Add(grid);
        }
    }
}